import axios from "axios";

const instanceECommerce = axios.create({
    baseURL:"http://127.0.0.1:8888/api/private/v1/",
    timeout:5000
})

function request(req){

    if(req.url != 'login'){
        instanceECommerce.interceptors.request.use(config=>{
            config.headers.Authorization = window.sessionStorage.getItem('token');
            console.log(config);
            return config;
        })
    }

    



    instanceECommerce.interceptors.response.use(res=>{
        console.log(res);
        if(res.config){
            return res.data
        }else{
            return res
        }
        
    })
    return new Promise((resovle,reject)=>{
        instanceECommerce(req).then(data=>{
            resovle(data)
        }).catch(err=>{
            reject(err);
        })
    })

}
export default request;